package com.tpu.osu.rating.service;

import java.util.List;

import com.tpu.osu.rating.Lector;
import com.tpu.osu.rating.Vote;
import com.tpu.osu.rating.dao.LectorDAO;
import com.tpu.osu.rating.dao.VoteDAO;

public class VoteServiceImpl implements VoteService
{

    private VoteDAO voteDAO;

    private LectorDAO lectorDAO;

    public void start() throws Exception
    {
        Lector lena = new Lector();
        lena.setName("MOKINA");

        lectorDAO.insert(lena);
    }

    public void stop() throws Exception
    {

    }

    public void setVoteDAO(VoteDAO aVoteDAO)
    {
        voteDAO = aVoteDAO;
    }

    public void setLectorDAO(LectorDAO aLectorDAO)
    {
        lectorDAO = aLectorDAO;
    }

    public void create(Vote aVote) throws Exception
    {

        if (aVote == null)
            throw new RuntimeException("vote can not be NULL");

        if (voteDAO.selectByPIN(aVote.getPin()) != null)
            throw new RuntimeException("hm... PIN already in use :)");

        if (lectorDAO.selectByName(aVote.getLector()) == null)
            throw new RuntimeException("unknown lector: " + aVote.getLector());

        voteDAO.insert(aVote);
    }

    public void delete(String aPIN) throws Exception
    {
        // TODO Auto-generated method stub

    }

    public List<Vote> findByGroup(String aGroup) throws Exception
    {
        // TODO Auto-generated method stub
        return null;
    }

    public Vote find(String aPIN) throws Exception
    {
        // TODO Auto-generated method stub
        return null;
    }

    public List<Vote> findByLector(String aLector) throws Exception
    {
        // TODO Auto-generated method stub
        return null;
    }

    public List<Vote> findByLectorAndGroup(String aLector, String aGroup) throws Exception
    {
        // TODO Auto-generated method stub
        return null;
    }

    public void update(Vote aVote) throws Exception
    {
        // TODO Auto-generated method stub

    }

}
